package com.zero;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
/**
 * 返回数据封装类
 */
@ApiModel("接口返回数据")
public class PublicResult {
    @ApiModelProperty("状态码")
    private int code;

    @ApiModelProperty("错误或失败提示")
    private String msg;

    @ApiModelProperty("详细信息")
    private Object data;

    public static PublicResult queryOk(Object data) {
        return PublicResult.resultEnums(ResultEnums.QUERY_OK, data);
    }

    public static PublicResult ok() {
        return PublicResult.resultEnums(ResultEnums.OK);
    }

    public static PublicResult queryFail(Object data) {
        return PublicResult.resultEnums(ResultEnums.QUERY_FAIL, data);
    }

    public static PublicResult fail(Object data) {
        return PublicResult.resultEnums(ResultEnums.FAIL, data);
    }

    public static PublicResult resultEnums(ResultEnums resultEnums, Object data) {
        if (null == data) {
            data = "";
        }
        return PublicResult.builder().code(resultEnums.getKey()).msg(resultEnums.getMsg()).data(data).build();
    }

    public static PublicResult resultEnums(ResultEnums resultEnums) {
        return resultEnums(resultEnums, null);
    }

    /**
     * 返回分页封装对象
     */
    @Data
    @Builder
    @ApiModel("分页返回")
    public static class PageResult {
        @ApiModelProperty("第几页")
        private int page;

        @ApiModelProperty("显示多少条")
        private int pageSize;

        @ApiModelProperty("总共多少条")
        private long total;

        @ApiModelProperty("详细信息")
        private Object data;
    }
}
